/*
 * Copyright 2010 Florian Sauter
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

//THIS SCRIPT IS INCLUDED IN application.js using http://closure-compiler.appspot.com/home.

/**
 * Returns the cookie value based on the passed cookie name.
 * 
 * @param cookieName the cookie name.
 * 
 * @returns String or null if no valid result was found.
 */
function getCookie(cookieName) {
  var results = document.cookie.match ( '(^|;) ?' + cookieName + '=([^;]*)(;|$)' );
  if(results) {
	return (unescape(results[2]));
  } else {
	return null;
  }
}

/**
 * Sets a new cookie.
 * 
 * @param keyName the cookie name.
 * @param value the cookie value.
 * @param expireTime the cookie expire time as int.
 * 
 * @returns void
 */
function setCookie(cookieName, value, expireTime) {
	var currentDate = new Date();
	var expireDate = new Date(currentDate.getTime() + expireTime);
	document.cookie = cookieName + '=' + value + '; expires=' + expireDate.toGMTString() + ';';
}

/**
 * Deletes a cookie based on the passed cookie name.
 * 
 * @param cookieName the cookie name.
 * @returns void
 */
function deleteCookie (cookieName) {
  var cookieDate = new Date ( );  // current date & time
  cookieDate.setTime ( cookieDate.getTime() - 1 );
  document.cookie = cookieName += "=; expires=" + cookieDate.toGMTString();
}